//
//  FriendlinNewCell.m
//  CheekiOS
//
//  Created by mac on 2017/6/9.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "FriendlinNewCell.h"

@interface FriendlinNewCell ()

@property (nonatomic, strong) UIImageView *headImageView;//头像
@property (nonatomic, strong) UIImageView *contentImage;//动态内容,视频
@property (nonatomic, strong) UILabel *ContentText;//动态文字


@property (nonatomic, strong) UILabel *nameLab;//名字
@property (nonatomic, strong) UILabel *contentLab;//动态内容
@property (nonatomic, strong) UILabel *timeLab;//时间
@property (nonatomic, strong) UILabel *linLab;
@end


@implementation FriendlinNewCell



+(instancetype)cellWithTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
    static NSString *str = @"FriendlinNewCellident";
    FriendlinNewCell *cell = [tableView dequeueReusableCellWithIdentifier:str];
    
    if (!cell) {
        cell = [[FriendlinNewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:str];
    }
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
     
        
        
        _headImageView = [[UIImageView alloc] init];
        _headImageView.layer.masksToBounds = YES;
        _headImageView.layer.cornerRadius = 22.5;
        _headImageView.contentMode = UIViewContentModeScaleAspectFill;
        [self addSubview:_headImageView];
        
        _nameLab = [[UILabel alloc] init];
        _nameLab.font = FontP(17);
        _nameLab.textColor = ColorI(0x5978b6);
        [self addSubview:_nameLab];
        
        _contentLab = [[UILabel alloc] init];
        _contentLab.font = FontP(15);
        _contentLab.textColor = ColorI(0x2e353f);
        [self addSubview:_contentLab];
        
        _timeLab = [[UILabel alloc] init];
        _timeLab.font = FontP(12);
        _timeLab.textColor = ColorI(0x802e353f);
        [self addSubview:_timeLab];
        
        _contentImage = [[UIImageView alloc] init];
        
        [self addSubview:_contentImage];
   
        _ContentText = [[UILabel alloc] init];
        _ContentText.font = FontP(12);
        _ContentText.textColor = ColorI(0x802e353f);
        [self addSubview:_ContentText];
        //87
        
        _linLab = [[UILabel alloc] init];
        _linLab.backgroundColor = TheLinColor;
        [self addSubview:_linLab];
        
        [self masLayout];
        
    }
    return self;
}


- (void)masLayout{

    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(self).offset(15);
        make.width.mas_equalTo(45);
        make.height.mas_equalTo(45);
    }];
    
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.left.equalTo(_headImageView.mas_right).offset(10);
        make.height.mas_equalTo(25);
    }];
    
    [_contentLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLab.mas_bottom).offset(3);
        make.left.equalTo(_headImageView.mas_right).offset(10);
        make.height.mas_equalTo(25);

    }];
    
    [_timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_contentLab.mas_bottom).offset(0);
        make.left.equalTo(_headImageView.mas_right).offset(10);
        make.height.mas_equalTo(25);
    }];
    
    [_contentImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.width.mas_equalTo(67);
        make.height.mas_equalTo(67);
        make.right.equalTo(self).offset(-15);
    }];
    
    [_ContentText mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(10);
        make.width.mas_equalTo(67);
        make.height.mas_equalTo(67);
        make.right.equalTo(self).offset(-15);
    }];
    
    [_linLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-1);
        make.width.equalTo(self);
        make.height.mas_equalTo(1);
        
    }];
    

}

-(void)setModel:(FriendlinNewModel *)model{
    NSArray *arr = [NSArray array];
    
    if (model.img.length >0) {
            arr = [model.img componentsSeparatedByString:@","];
    }
    NSString *str = [NSString stringWithFormat:@"%@",model.circleType];
    
    if([str isEqualToString:@"1"]){
        _ContentText.hidden = NO;
        _contentImage.hidden = YES;
    }else{
        _ContentText.hidden = YES;
        _contentImage.hidden = NO;
    }

    [_headImageView sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(model.photo)] placeholderImage:[UIImage imageNamed:@"llustration"]];
    _nameLab.text = model.nickName;
    _contentLab.text = model.content;
    _timeLab.text = model.createTime;
    
    _ContentText.text = model.commentContent;
    if (arr.count>0) {
        [_contentImage sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(arr[0])] placeholderImage:[UIImage imageNamed:@"llustration"]];

    }

}
@end
